﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Shell32;

namespace Media
{
    /// <summary>
    /// Create the AMediaInfo instance with a filepath
    /// </summary>
    class MediaInfoFactory
    {
        /// <summary>
        /// Create an instance of AMediaInfo corresponding to the info of the file contains by the path
        /// </summary>
        /// <param name="path">path of the media file</param>
        /// <returns>Object containing all neccessary informations about the media file or null if not valid object</returns>
        public static AMediaInfo getInfoOfMedia(String path)
        {
            if (path != null)
            {
                try
                {
                        TagLib.File file = TagLib.File.Create(path);
                        if (file != null && file.Properties != null)
                        {
                            if (file.Properties.MediaTypes.ToString() == "Audio")
                                return new MusicInfo(path, file);
                            else if (file.Properties.MediaTypes.ToString() == "Audio, Video")
                                return new MovieInfo(path, file);
                            else if (file.Properties.MediaTypes.ToString() == "Photo")
                                return (new PictureInfo(path, file));
                        }
                }
                catch (TagLib.UnsupportedFormatException e)
                {
                    return (null);
                }
            }
            return (null);
        }
    }
}
